<script type="text/javascript" language="javascript">
    function showCP(id) {
        var sel = $("#" + id);
        if (sel.size() == 1) {
            $('#cp_content').html(sel.html());
        }
    }

    function file_edit(id) {

        $("#file_id_" + id).hide();
        $("#file_ul_id_" + id).show();
    }

    $(document).ready(function() {
        $('#file_upload').click(function () {
            if ($('#file_keywords').val() == null) {
                alert('Keyword Cannot be empty!');
                return false;
            }
        });
    <?php
    $action = (isset($_GET['action'])) ? $_GET['action'] : '';
    if (!empty($action)) {
        echo 'showCP(\'' . $action . '\');';
    }
    ?>

        $('.do_action').click(function () {
            if (!confirm('Are you sure?')) {
                return false;
            }
        });
    });
</script>

<div id="cp_container">
<p id="cp_title" align="center">User Control Panel</p>
<table width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <th id="cp_leftContainer" valign="top" style="padding-right:1em;margin:0 10px">
            <p class="cp_options" onclick="showCP('cp_upload')">Upload File</p>

            <p class="cp_options" onclick="showCP('cp_upload_img')">Upload Image</p>

            <p class="cp_options" onclick="showCP('cp_editFile')">Edit Files</p>

            <p class="cp_options" onclick="showCP('cp_editProf')">Edit Profile</p>

            <? if ($_user_type == 1): ?>

            <hr style="background-color:#add8e6;color:#add8e6;border:none;height:2px"/>

            <p class="cp_options" onclick="showCP('cp_manaUser')">Manage User</p>

            <p class="cp_options" onclick="showCP('cp_manaFile')">Manage Files</p>

            <p class="cp_options" onclick="showCP('cp_viewComp')">Manage Complains</p>

            <p class="cp_options" onclick="showCP('cp_ssword')">Manage Stop/Stemming Words</p>
            <? endif ?>
        </th>
        <th id="cp_content" valign="top" style="padding-left:1em">
            <p style="width:100%; text-align:center;">Welcome to Control Panel Home</p>
        </th>
    </tr>
</table>
<!--
    -FILE UPLOAD
-->
<div id="cp_upload" style="display:none;">
    <h2>Upload Your file.</h2>
    <?=form_open_multipart('./user_cp/upload_file')?>
    <fieldset>
        <legend>Pick a File</legend>
        <?=form_upload('userfile')?>
    </fieldset>
    <fieldset>
        <legend>File Information</legend>
        <label style="color:gray;">Enter one or more keyword for your file</label><br/>
        <?=form_input(array('id' => 'file_keywords', 'name' => 'file_keywords', 'size' => '30'))?>
        <br/><label style="color:gray;">Select Permission</label><br/>
        <?=form_dropdown('file_permission', array('0' => 'Private', '1' => 'Public'))?>
    </fieldset>

    <?=form_submit('file_upload', 'Upload') . form_close()?>
</div>
<!--
    -FILE UPLOAD
-->

<div id="cp_upload_img" style="display:none;">
    <h2>Upload Your Image.</h2>
    <?=form_open_multipart('./user_cp/upload_file')?>
    <fieldset>
        <legend>Pick a File</legend>
        <?=form_upload('userfile')?>
    </fieldset>
    <?=form_submit('image_upload', 'Upload') . form_close()?>
</div>


<div id="cp_editFile" style="display:none;">
    <h2>Edit File</h2>
    <?
    if ($file_query->num_rows() > 0) {
        foreach ($file_query->result() as $row)
        {
            ?>
            <div id="file_id_<?=$row->file_id?>" style="text-align:right">
                <a href="<?=$row->file_dir?>"
                <span style="font-size:30px"><?=$row->file_name?></span>
                </a>
                <span style=""><?=$row->file_last_update?></span>
                    <span style="margin:0 20px" class="file_edit_btn"
                          onclick="file_edit('<?=$row->file_id?>')">EDIT</span>
            </div>
            <div id="file_ul_id_<?=$row->file_id?>" style="display:none;">
                <?=form_open_multipart('./user_cp/update_file')?>
                <?=form_upload('userfile')?>
                <?=form_input('file_keywords')?>
                <?=form_dropdown('file_permission', array('0' => 'Private', '1' => 'Public'))?>
                <?=form_hidden('file_id', $row->file_id)?>
                <?=form_submit('file_upload', 'Upload')?>
                <?=form_close()?>
            </div>
            <hr/>
            <br/>
            <?
        }
    }
    ?>
</div>

<div id="cp_editProf" style="display:none;">
    <?
    if ($user_query->num_rows() == 1) {
        $user_data = $user_query->row(0);
        ?>
        <div>
            <?= form_open('login/update_prof') ?>
            <fieldset style="padding:10px 30px">
                <legend>Edit Profile</legend>
                <fieldset class="update_field">
                    <legend>Information</legend>
                    <label>Password</label>
                    <?=form_password(array('name' => 'reg_pw', 'class' => 'update_text'), set_value('reg_pw', ''))?>
                    <label>Password Confirmation</label>
                    <?=form_password(array('name' => 'reg_pw2', 'class' => 'update_text'), set_value('reg_pw2', ''))?>
                    <label>Email</label>
                    <?=form_input(array('name' => 'reg_email', 'class' => 'update_text'), set_value('reg_email', $user_data->email))?>
                    <label>First Name</label>
                    <?=form_input(array('name' => 'reg_first_name', 'class' => 'update_text'), set_value('reg_first_name', $user_data->first_name))?>
                    <label>Last Name</label>
                    <?=form_input(array('name' => 'reg_last_name', 'class' => 'update_text'), set_value('reg_last_name', $user_data->last_name))?>
                    <label>Age</label>
                    <?=form_input(array('name' => 'reg_age', 'class' => 'update_text'), set_value('reg_age', $user_data->age))?>
                    <label>School</label>
                    <?=form_input(array('name' => 'reg_school', 'class' => 'update_text'), set_value('reg_school', $user_data->school))?>
                </fieldset>
                <br/>
                <input id="update_submit" value="Submit and Update" type="submit"/>
                <input id="update_reset" value="Reset" type="reset"/>
            </fieldset>
            <?= form_close() ?>
        </div>
        <?
    }
    ?>
</div>




<? if ($_user_type == 1): ?>
<div id="cp_manaUser" style="display:none;">
    <h2>Manage User</h2>
    <table width="100%" border="1px" cellspacing="0" cellpadding="0">
        <tr>
            <td class="manage_user_title">UserName</td>
            <td class="manage_user_title">Email</td>
            <td class="manage_user_title">First Name</td>
            <td class="manage_user_title">Last Name</td>
            <td class="manage_user_title">School</td>
            <td class="manage_user_title">Age</td>
            <td class="manage_user_title">Points</td>
            <td class="manage_user_title">B</td>
            <td class="manage_user_title">A</td>
            <td class="manage_user_title">Action</td>
        </tr>
        <?
        if ($admin_user_query->num_rows() > 0) {
            foreach ($admin_user_query->result() as $row)
            {
                ?>
                <tr>
                    <td class="manage_user"><?=$row->username?></td>
                    <td class="manage_user"><?=$row->email?></td>
                    <td class="manage_user"><?=$row->first_name?></td>
                    <td class="manage_user"><?=$row->last_name?></td>
                    <td class="manage_user"><?=$row->school?></td>
                    <td class="manage_user"><?=$row->age?></td>
                    <td class="manage_user"><?=$row->point?></td>
                    <td class="manage_user"><?=$row->blocked?></td>
                    <td class="manage_user"><?=$row->approved?></td>
                    <td class="manage_user">
                        <a class="do_action" href="<?=site_url('user_cp/manage_user/1/' . $row->id)?>">Approve</a>
                        |
                        <a class="do_action" href="<?=site_url('user_cp/manage_user/2/' . $row->id)?>">Remove</a>
                    </td>
                </tr>
                <?
            }
        }
        ?>
    </table>
</div>

<div id="cp_manaFile" style="display:none;">
    <h2>Manage Files</h2>

    <h3>Files</h3>
    <table width="100%" border="1px" cellspacing="0" cellpadding="0">
        <tr>
            <td class="manage_user_title">Name</td>
            <td class="manage_user_title">Owner</td>
            <td class="manage_user_title">Approved</td>
            <td class="manage_user_title">Action</td>
        </tr>
        <?
        if ($admin_file_query->num_rows() > 0) {
            foreach ($admin_file_query->result() as $row)
            {
                ?>
                <tr>
                    <td class="manage_user"><?=$row->file_name?></td>
                    <td class="manage_user"><?=$row->file_owner_username?></td>
                    <td class="manage_user"><?=$row->file_approved?></td>
                    <td class="manage_user">
                        <a class="do_action"
                           href="<?=site_url('user_cp/manage_file/1/1/' . $row->file_id)?>">Approve</a>
                        |
                        <a class="do_action" href="<?=site_url('user_cp/manage_file/2/1/' . $row->file_id)?>">Remove</a>
                    </td>
                </tr>
                <?
            }
        }
        ?>
    </table>
    <h3>Images</h3>
    <table width="100%" border="1px" cellspacing="0" cellpadding="0">
        <tr>
            <td class="manage_user_title">Name</td>
            <td class="manage_user_title">Owner</td>
            <td class="manage_user_title">Approved</td>
            <td class="manage_user_title">Action</td>
        </tr>
        <?
        if ($admin_image_query->num_rows() > 0) {
            foreach ($admin_image_query->result() as $row)
            {
                ?>
                <tr>
                    <td class="manage_user"><?=$row->name?></td>
                    <td class="manage_user"><?=$row->owner?></td>
                    <td class="manage_user"><?=$row->approved?></td>
                    <td class="manage_user">
                        <a class="do_action" href="<?=site_url('user_cp/manage_file/1/2/' . $row->id)?>">Approve</a>
                        |
                        <a class="do_action" href="<?=site_url('user_cp/manage_file/2/2/' . $row->id)?>">Remove</a>
                    </td>
                </tr>
                <?
            }
        }
        ?>
    </table>
</div>

<div id="cp_viewComp" style="display:none;">
    <h2>View Complains</h2>
    <table width="100%" border="1px" cellspacing="0" cellpadding="0">
        <tr>
            <td class="manage_user_title">Complain To</td>
            <td class="manage_user_title">Own By</td>
            <td class="manage_user_title">Complain Content</td>
            <td class="manage_user_title">Action</td>
        </tr>
        <?
        if ($admin_comp_query->num_rows() > 0) {
            foreach ($admin_comp_query->result() as $row)
            {
                ?>
                <tr>
                    <td class="manage_user"><?=$row->to?></td>
                    <td class="manage_user"><?=$row->to_user?></td>
                    <td class="manage_user"><?=form_textarea(array('name'=>'','rows'=>'4','cols'=>'30'), $row->content)?></td>
                    <td class="manage_user">
                        <a class="do_action"
                           href="<?=site_url('user_cp/warn_user/' . $row->to_user . '/' . $row->id)?>">Warn</a>
                        |
                        <a class="do_action"
                           href="<?=site_url('user_cp/remove_complain/' . $row->id)?>">Remove</a>
                    </td>
                </tr>
                <?
            }
        }
        ?>
    </table>
</div>

<div id="cp_ssword" style="display:none;">
    <h2>Manage Stop/Stemming Word</h2>

    <fieldset>
        <legend>Stop Word</legend>
        <label>Add a stop word</label>
        <?
        echo form_open(site_url('user_cp/add_stopword/'));
        echo form_input('stopword');
        echo form_submit('', 'ADD');
        echo form_close();
        ?>
        <br/>
        <table width="100%" border="1px" cellspacing="0" cellpadding="0">
            <tr>
                <td class="manage_user_title">Word</td>
                <td class="manage_user_title">Action</td>

            </tr>
            <?
            if ($admin_stopword_query->num_rows() > 0) {
                foreach ($admin_stopword_query->result() as $row)
                {
                    ?>
                    <tr>
                        <td class="manage_user"><?=$row->word?></td>
                        <td class="manage_user">
                            <a class="do_action"
                               href="<?=site_url('user_cp/remove_stopword/' . $row->word)?>">Remove</a>
                        </td>
                    </tr>
                    <?
                }
            }
            ?>
        </table>
    </fieldset>
    <fieldset>
        <legend>Stemming Word</legend>
        <label>Add root word</label>
        <?
        echo form_open(site_url('user_cp/add_stemword/'));
        echo form_input('stemword');
        echo form_hidden('isroot', '1');
        echo form_submit('', 'ADD');
        echo form_close();
        ?>
        <br/>
        <table width="100%" border="1px" cellspacing="0" cellpadding="0">
            <tr>
                <td class="manage_user_title">Word</td>
                <td class="manage_user_title">Root?</td>
                <td class="manage_user_title">Belong</td>
                <td class="manage_user_title">Action</td>

            </tr>
            <?
            if ($admin_stemword_query->num_rows() > 0) {
                foreach ($admin_stemword_query->result() as $row)
                {
                    ?>
                    <tr>
                        <td class="manage_user"><?=$row->word?></td>
                        <td class="manage_user"><?=$row->isroot?></td>
                        <td class="manage_user"><?=$row->belong?></td>
                        <td class="manage_user">
                            <?if ($row->isroot == '1') {
                            echo form_open(site_url('user_cp/add_stemword/'));
                            echo form_input('stemword');
                            echo form_hidden('root', $row->word);
                            echo form_hidden('isroot', '0');
                            echo form_submit('', 'ADD');
                            echo form_close();
                        }

                            ?>
                            <a class="do_action"
                               href="<?=site_url('user_cp/remove_stemword/' . $row->word)?>">Remove</a>
                        </td>
                    </tr>
                    <?
                }
            }
            ?>
        </table>
    </fieldset>
</div>
    <?php endif ?>
</div>
<br/>